package hikari.objects3d;

import org.swig.jirr.IMeshSceneNode;
import org.swig.jirr.ISceneManager;
import org.swig.jirr.ISceneNode;
import org.swig.jirr.ITriangleSelector;
import org.swig.jirr.SColor;

/**
 * @author sad
 */
public class Sphere3dObject extends GeometricObject {
    
    public Sphere3dObject(ISceneManager sceneManager) {
        super("Sphere", true);
        initObject(sceneManager);
    }

    public Sphere3dObject(String name, ISceneManager sceneManager) {
        super(name);
        initObject(sceneManager);
    }

    public Sphere3dObject(String name, IMeshSceneNode sceneNode) {
        super(name);
        setMeshSceneNode(sceneNode);
    }

    private void initObject(ISceneManager sceneManager) {
        ISceneNode sphereMesh = createSceneNode(sceneManager);
        setMeshSceneNode(sphereMesh);
    }

    public static IMeshSceneNode createSceneNode(ISceneManager sceneManager) {
        IMeshSceneNode sphereMesh = sceneManager.addSphereSceneNode(3);
        sphereMesh.getMaterial(0).setEmissiveColor(SColor.randomColor());
        ITriangleSelector selector = sceneManager.createTriangleSelector(sphereMesh.getMesh(), sphereMesh);
        sphereMesh.setTriangleSelector(selector);
        sphereMesh.setParent(sceneManager.getRootSceneNode());
        return sphereMesh;
    }

    @Override
    public String objectType() {
        return "sphere";
    }
}
